import sys, getopt

def parse_command_line():
    """
        add usage text here
    """
    optdict = {
        'args'          : [],
        'arg_required'  : False,    # a:
        'not_required'  : False,    # n
        'required'      : False,    # r
        'foo'           : 'bar',    # foo=
    }

    try:
        args = sys.argv[1:]
        optlist, args = getopt.getopt(args, 'a:nr', ['foo='])
    except Exception, e:
        f = "\n\tERROR:%s\n%s\n"
        sys.stderr.write(f % (e, parse_command_line.__doc__))
        sys.exit(1)

    for opt,val in optlist:
        if opt == '--foo':
            optdict['foo'] = val
        elif opt == '-a':
            optdict['arg_required'] = val
        elif opt == '-n':
            optdict['not_required'] = True
        elif opt == '-r':
            optdict['required'] = True

    optdict['args'] = args

    if not optdict['arg_required'] or not optdict['required']:
        f = "\n\t-a=<val> and -r parameters required to run\n%s\n"
        sys.stderr.write(f % (parse_command_line.__doc__))
        sys.exit(1)

    return optdict

optdict = parse_command_line()
print optdict

